﻿interface Utility {
    /**
     * Displays a dialog box containing an application-defined message.
     * Remarks: This method is only available for Updated entities.
     * @param message The text of the message to display in the dialog.
     * @param onCloseCallback A function to execute when the OK button is clicked.
     * @returns {} 
     */
    alertDialog(message: string, onCloseCallback? : NoneParamCallback): void;

    /**
     * Displays a confirmation dialog box that contains an optional message as well as OK and Cancel buttons.
     * Remarks: This method is only available for Updated entities.
     * @param message The text of the message to display in the dialog
     * @param yesCloseCallback A function to execute when the OK button is clicked.
     * @param noCloseCallback A function to execute when the Cancel button is clicked.
     * @returns {} 
     */
    confirmDialog(message: string, yesCloseCallback?: NoneParamCallback, noCloseCallback?: NoneParamCallback): void;

    /**
     * Returns the barcode information, such as a product number, scanned using the device camera.
     * @returns {} 
     */
    getBarcodeValue(): BarcodeValue;

    /**
     * Returns the current location using the device geolocation capability.
     * @returns {} 
     */
    getCurrentPosition(): void;

    /**
    * Determine if an entity is an activity entity.
    * @returns {boolean}
    **/
    isActivityType(entityName: string): boolean;

    /**
    * Opens an entity form for a new or existing entity record using the options you set as parameters.
    **/
    openEntityForm(name: string, id?: string, parameters?: Array<Parameters>, windowOptions?: WindowOptions): void;

    /**
    * For Microsoft Dynamics CRM Online 2015 Update 1 or later use this function to open a new quick create form. You can use this function to set default values using attribute mappings or for specific attributes. If the user saves the record, you can capture a reference to the record created.
    **/
    openQuickCreate(entityLogicalName: string, createFromEntity?: Lookup, parameters?: Array<Parameters>): QuickCreate;

    /**
    * Opens an HTML web resource.
    * This function will not work with Microsoft Dynamics CRM for tablets.
    **/
    openWebResource(webResourceName: string, webResourceData?: string, width?: number, height?: number): Window;
}

interface BarcodeValue {
    /**
     * 
     * @param successCallback A function to call when the barcode value is returned.
     * @param errorCallback A function to call when the operation fails. An error object with the message property will be passed that describes the error details.
     * @returns {} 
     */
    then(successCallback: Callback<string>, errorCallback: Callback<Message>): void;
}

interface Parameters {
    [index:string] : string;
}

interface WindowOptions {
    /**
    * Open a new account record using the default form in a new window
    **/
    openInNewWindow: boolean;
}

interface QuickCreate {
    then(successCallback?: Callback<Lookup>, errorCallback?: Callback<CodeMessage>);
}

interface Callback<T> {
    (result: T): void;
}

interface Message {
    /**
    * 
    **/
    message: string;
}

interface CodeMessage {
    /**
    * The error code
    **/
    errorCode: number;

    /**
    * A localized error message
    **/
    message: string;
}